﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cangku.Model;
using Cangku.BLL;

namespace Cangku
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 出库按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSto_Click(object sender, EventArgs e)
        {
            //获取用户输入的参数
            string shopId = ShopId.Text;
            string num = StorageNum.Text;
            int n = 0;
            lbMsg1.Text = shopId == "" ? "商品编号必须输入" : "";
            lbMsg2.Text = num == "" ? "出库数量必须输入" : "";
            if (shopId != "" && num != "")
            {
                if (!int.TryParse(num, out n) || n <= 0)
                {
                    lbMsg2.Text = "出库数量必须输入数字并且大于0";
                }
                else
                {
                    var id = ShopInfoBLL.GetIdByShopId(shopId);
                    if (id==-1)
                    {
                        Response.Write("<script>alert('商品编号不存在')</script>");
                        return;
                    }
                    tb_storage sto = new tb_storage()
                    {
                        shopId = id,
                        storageQuantity = n,
                        storageDtm = DateTime.Now
                    };
                    if (ShopInfoBLL.AddStorage(sto))
                    {
                        Response.Write("<script>alert('出库成功')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('出库失败')</script>");
                    }
                }
            }
            
        }
    }
}